Attribute VB_Name = "ModFungsi"
Public Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Const WM_CLOSE = &H10
Public IP As String, Situs As String
Public X As String, Judul As String

Public Sub LoadFileHost(list As ListBox, Namafile As String)
Dim linestr As String, tmp() As String
On Error Resume Next
    Open Namafile For Input As #1
        While Not EOF(1)
          Line Input #1, linestr
        tmp = Split(linestr, vbTab)
        IP = tmp(0)
        Situs = tmp(1)
        DoEvents
            list.AddItem Situs
        Wend
    Close #1
End Sub
Public Sub Load_Caption(list As ListBox, Namafile As String)
Dim linestr As String, tmp() As String
On Error Resume Next
Open Namafile For Input As #1
    While Not EOF(1)
        Line Input #1, linestr
        Judul = linestr
    DoEvents
        list.AddItem Judul
    Wend
Close #1
End Sub


Public Sub SaveFileHost(list As ListBox, place As String)
On Error Resume Next
Dim simpan As Long
    Open place For Output As #1
        For simpan = 0 To list.ListCount - 1
            Print #1, "127.0.0.1" & vbTab & list.list(simpan)
        Next
    Close #1
End Sub
Public Sub SaveCaption(list As ListBox, place As String)
On Error Resume Next
Dim simpan As Long
    Open place For Output As #1
        For simpan = 0 To list.ListCount - 1
            Print #1, list.list(simpan)
        Next
Close #1
End Sub


Public Sub hapus(list As ListBox, place As String)
On Error Resume Next
Dim hapus As Long
Open place For Output As #1
  For hapus = 0 To list.ListCount - 1
    Print #1, "127.0.0.1" & vbTab & list.list(hapus)
  Next
Close #1
End Sub

Public Sub HapusCaption(list As ListBox, place As String)
On Error Resume Next
Dim hapus As Long
Open place For Output As #1
    For hapus = 0 To list.ListCount - 1
        Print #1, list.list(hapus)
    Next
Close #1
End Sub


Public Sub backup()
FileCopy GetSystemPath & "\Drivers\etc\Hosts", App.Path & "\back.pid"
Open GetSystemPath & "\Drivers\etc\Hosts" For Output As #1
    Print #1, "127.0.0.1          localhost"
Close #1
End Sub
Public Sub mulai()
On Error Resume Next
FileCopy App.Path & "\back.pid", GetSystemPath & "\Drivers\etc\hosts"

End Sub


Public Function GetSystemPath() As String

On Error Resume Next
Dim Buffer As String * 255
Dim X As Long
    X = GetSystemDirectory(Buffer, 255)
    GetSystemPath = Left(Buffer, X) & "\"
    
End Function

Public Function Hajar(target As String)
Dim H As Long
Dim t As String * 255
H = GetForegroundWindow
GetWindowText H, t, 255
If InStr(UCase(t), UCase(target)) > 0 Then
    SendMessage H, WM_CLOSE, 0, 0
'MsgBox "Maaf perintah yang coba anda jalankan telah dinonaktifkan oleh administrator komputer ini. Silahkan menghubungi administrator untuk mengaktifkannya kembali", vbInformation + vbOKOnly, "Pembatasan"
End If
End Function


Public Sub Tonjok(target As String)
Dim H As Long
Dim t As String * 255
H = GetForegroundWindow
GetWindowText H, t, 255

If InStr(UCase(t), UCase(target)) > 0 Then
    SendMessage H, WM_CLOSE, 0, 0
End If
End Sub

Public Sub kill_IE(target As String)
Dim H As Long
Dim t As String * 255
H = GetForegroundWindow
GetWindowText H, t, 255

If InStr(UCase(t), UCase(target)) > 0 Then
Shell App.Path & "\kill.bat", vbHide
End If
End Sub



